package com.richapp.launcher.ui.fragments.home;

import com.richapp.launcher.R;
import com.richapp.launcher.ui.adapter.MainFragmentAdapter;
import com.richapp.launcher.ui.fragments.BaseFragment;
import com.richapp.launcher.ui.view.PageIndicator;
import com.richapp.launcher.ui.view.TabPageView;

import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

public class Tabs_Fragment extends BaseFragment {
	private TabPageView mTabPageView = null;
	private PageIndicator mIndicator = null;
	private ViewPager mViewPager = null;
    private MainFragmentAdapter mAdapter = null; 
    private View smartHomeTabs = null;
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		if (smartHomeTabs == null) {
			smartHomeTabs = inflater.inflate(R.layout.smarthometabs,
					container, false);
			init(smartHomeTabs);
		}
		return smartHomeTabs;
	}

	
	
	@Override
	public void onResume() {
		if (mTabPageView!=null) {
			mTabPageView.getCurrTabView().requestFocus();
		}
		super.onResume();
	}



	@Override
	public void onDestroyView() {
		((ViewGroup)smartHomeTabs.getParent()).removeView(smartHomeTabs);
		super.onDestroyView();
	}

	@Override
	protected void init(View view) {
		mViewPager = (ViewPager) view.findViewById(R.id.pager);
		mTabPageView = (TabPageView) view.findViewById(R.id.tabPageView);
		mIndicator = mTabPageView.getTabPageIndicator();
		mViewPager.setOffscreenPageLimit(1);
		mAdapter = new MainFragmentAdapter(getActivity().getSupportFragmentManager());
		mViewPager.setAdapter(mAdapter);
		mIndicator.setViewPager(mViewPager);
	}
}
